package com.gt.web.api.common;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Generated;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;

/**
 * <p>
 * EZRResult
 * </p>
 *
 * @author: WeiHuan
 * @version:1.0
 * @date: 2024/2/3 12:40
 * 注意：本内容仅限于公司内部传阅，禁止外泄以及用于其他的商业目的
 */
@Getter
@Setter
@ToString
public class R<T> implements Serializable {

    @ApiModelProperty(notes = "状态码")
    private Integer code;
    @ApiModelProperty(notes = "响应消息")
    private String msg;
    @ApiModelProperty(notes = "数据")
    private T data;

    public Integer getCode() {
        return this.code == null ? 200 : this.code;
    }

    public String getMsg() {
        return this.msg == null ? "success" : this.msg;
    }

    public R() {
    }

    public R(T data) {
        this.data = data;
    }

    public R(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Generated
    public R(Integer code, String message, T data) {
        this.code = code;
        this.msg = message;
        this.data = data;
    }

    @Generated
    public String toString() {
        Integer var10000 = this.getCode();
        return "Result(code=" + var10000 + ", message=" + this.getMsg() + ", data=" + this.getData() + ")";
    }

    public static <T> R<T> ok(T data) {
        return new R(data);
    }

    public static R OK = new R();

    public static <T> R<T> fail(Integer code, String msg) {
        return new R(code, msg);
    }

    public static <T> R<T> fail(String msg) {
        return fail(500, msg);
    }
}